package CollectionDemo;

import java.util.ArrayList;
import java.util.Collection;

public class Demo {
    public static void main(String[] args) {
        Collection<String>collection = new ArrayList<>();
        collection.add("aaa");
        collection.add("bbb");
        collection.add("ccc");
        collection.add("dddd");
        System.out.println(collection);

        boolean remove = collection.remove("aaa");
        System.out.println(remove);
        System.out.println(collection);

        //根据条件进行删除
        collection.removeIf((String s )->{
           return s.equals("bbb");
        });
        System.out.println(collection);

        //清空集合
        collection.clear();
        System.out.println(collection);

        //判断集合是否为空
        boolean empty = collection.isEmpty();
        System.out.println(empty);

        //判断集合长度
        int size = collection.size();
        System.out.println(size);


        collection.add("aaa");
        collection.add("bbb");
        collection.add("ccc");
        //判断集合是否存在指定的元素
        boolean contains = collection.contains("dddd");
        System.out.println(contains);
    }
}
